package thinkinjava4.ch22_gui;


import javax.swing.*;
import java.awt.*;
import java.util.HashMap;
import java.util.Map;

public class TextArea extends JFrame {
    private JButton b = new JButton("Add Data");
    private JButton c = new JButton("Clear Data");
    private JTextArea t = new JTextArea(20, 40);
    private Map<String, String> m = new HashMap<>();

    public TextArea() {
        m.put("a", "1");
        m.put("b", "2");
        m.put("c", "3");
        m.put("d", "4");
        m.put("e", "5");
        m.put("f", "6");
        b.addActionListener(event -> {
            for (Map.Entry me : m.entrySet()) t.append(me.getKey() + ": " + me.getValue() + "\n");
        });
        c.addActionListener(event -> t.setText(""));
        setLayout(new FlowLayout());
        add(new JScrollPane(t));
        add(b);
        add(c);
    }

    public static void main(String[] args) {
        SwingConsole.run(new TextArea(), 475, 425);
    }
}
